#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	char a[1000];
	gets(a);
	int len = strlen(a);
	a[len] = ' ';
	int len1 = 0;
	int maxlen = 0, minlen = len;
	int maxend = 0;
	int minend = 0;
	int end;
	for (int i = 0; a[i] != '\0'; i++) {
		if (isalpha(a[i])) {
			len1++;
		} else {
			end = i;
			if (len1 > maxlen) {
				maxlen = len1;
				maxend = i;
			}
			if (len1 < minlen) {
				minlen = len1;
				minend = i;
			}
			len1 = 0;
		}

	}
	for (int i = maxend - maxlen; i < maxend; i++) {
		putchar(a[i]);
	}
	putchar('\n');
	for (int i = minend - minlen; i < minend; i++) {
		putchar(a[i]);
	}
	return 0;
}